<?php

namespace Apps\Common\Models;

/**
 * 美粒宝典Model
 * @author     chenxiaolin
 * @date        2016年1月19日
 * @version     2.0.0
 * @copyright   Copyright 2016 meelier.com
 */
 
class CosBeautyCanon extends \PhalconPlus\Database\Model{
	public $id;
	public $title;
	public $content;
	public $img_url;
	public $settime;
	public $fit;
	public $assist;
	public $setman;
	public $state;
	public $city_id;
	public $summary;
	
	public function getSource()
	{
		return 'beauty_canon';
	}
	
	public static function find($parameters = null)
	{
		return parent::find($parameters);
	}
	
	public static function findFirst($parameters = null)
	{
		return parent::findFirst($parameters);
	}
	
	public function columnMap()
	{
		return array(
				'id' => 'id',
				'title' => 'title',
				'content' => 'content',
				'img_url' => 'img_url',
				'settime' => 'settime',
				'fit' => 'fit',
				'assist' => 'assist',
				'setman' => 'setman',
				'state' => 'state',
		        'city_id' => 'city_id',
		        'summary' => 'summary'  
		);
	}
	
	/*
	 *更新美粒宝典点赞数
	 */
	public static function updateAssist($id)
	{
		$sql = 'UPDATE beauty_canon SET assist = (SELECT COUNT(*) FROM cos_beauty_canon_assist WHERE beauty_canon_id=beauty_canon.id) WHERE id = :bc_id';
		$model = new self;
		return $model->getWriteConnection()->execute($sql, ['bc_id' => $id]);
	}
	
	
}
